package org.example.simplemanagementsystem.controller;

import org.example.simplemanagementsystem.pojo.*;
import org.example.simplemanagementsystem.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;
    @GetMapping
    public Result page(EmpQueryParam empQueryParam) {
        PageResult pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }
    /**
     * 添加员工
     */
    @PostMapping
    public Result save(@RequestBody Emp emp) {
        empService.save(emp);
        return Result.success();
    }
    /**
     * 删除员工
     * @param ids 员工编号
     */
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids) {
        empService.deleteByIds(ids);

        return Result.success();
    }
    /**
     * 查询员工信息
     */
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        Emp emp = empService.getInfo(id);
        return Result.success(emp);
    }
    /**
     * 更新数据
     */
    @PutMapping
    public Result update(@RequestBody Emp emp) {
        empService.update(emp);
        return Result.success();
    }

    /**
     * 列出所有的员工数据
     * @return
     */
    @GetMapping("/list")
    public Result getList() {
        List<Emp> emplist =  empService.getList();
        return Result.success(emplist);
    }
}
